package 左哥算法.ch12滑动窗口与双端队列;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class 最长不重复子序列 {
    static Map<Integer, Integer> index = new HashMap<>();
    static int max = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < nums.length; i++) {
            nums[i]=sc.nextInt();
        }
        for (int l = 0, r = 0; r < nums.length; r++) {
            Integer i = index.get(nums[r]);
            if (i!=null) {
                while (l<=i){
                    index.remove(nums[l]);
                    l++;
                }
            }
            index.put(nums[r],r);
            max=Math.max(max,r-l+1);
        }
        System.out.println(max);
    }
}
